import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            name: "home",
            path: "/home",
            component: () => import('@/views/home.vue')
        }, {
            name: "news",
            path: "/news",
            component: () => import('@/views/news.vue'),
            children: [
                {
                    name: "detail",
                    // path: 'detail/:id/:title/:content',//这是params传参要占位符
                   path:'detail',
                    component: () => import('@/views/Detail.vue'),
                    // 第一种写法 可以将路由收到的params参数作为组件的props传递
                    // props: true
                    // 第二种函数式 适用于其他一切
                    props(route)
                    {
                        console.log(route);
                        return route.query
                    }
                    // 第三种 对象式 写自定义属性
                    // props:{
                    //     x:100,
                    //     y:20
                    // }
                }
            ]
        }, {
            name: "about",
            path: "/about",
            component: () => import('@/views/about.vue')
        },{
            path:"/",
            redirect:"/home"
        }
    ]

})
export default router